<?php

namespace app\admin\controller;

class Dashboard extends Base
{

    public function index(){
        $countData = $this->getCountData();

        $this->assign('countData', $countData);
        $title = '江陵县住建局';
        $this->assign('title', $title);

        return $this->view->fetch('index');
    }

    /**
     * 今日&当月 统计数据
     */
    public function getCountData(){
        $where = [];
        // 今日信访用户
        $userModel = model('User');
        $userDayWhere = [
            'type' => 2,
        ];
        $todayUser = $userModel->where($where)->where($userDayWhere)->whereTime('createDate', 'today')->count();
        // 累计已信访人数
        $totalUser = $userModel->where($where)->where(['type' => 2, 'status' => 1])->count();

        // 今日信访件
        $letterModel = model('Letter');
        $letterDayWhere = [
            'status' => ['neq', 2],
        ];
        $todayLetter = $letterModel->where($where)->where($letterDayWhere)->whereTime('createDate', 'today')->count();
        // 累计提交信访件
        $totalLetter = $letterModel->where($where)->where(['status' => ['neq', 2]])->count();

        // 今日文件通知
        $policyModel = model('Policy');
        $policyDayWhere = [
            'status' => 1,
        ];
        $todayPolicy = $policyModel->where($where)->where($policyDayWhere)->whereTime('createDate', 'today')->count();
        // 累计发布文件通知
        $totalPolicy = $policyModel->where($where)->where(['status' => 1])->count();

        $countData = [
            'todayUser' => $todayUser,
            'totalUser' => $totalUser,
            'todayLetter' => $todayLetter,
            'totalLetter' => $totalLetter,
            'todayPolicy' => $todayPolicy,
            'totalPolicy' => $totalPolicy,
        ];

        return $countData;
    }

}